package com.example.petcare.mapper;


import com.example.petcare.pojo.Goods;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BuyMapper {



    // 添加增值商品到购物车
    @Insert("insert into cart_item (host_id, g_id) values (#{hostId}, #{gId})")
    void addGoodsToCart(Integer gId, Integer hostId);

    // 先在购物车里查询是否已经存在该商品
    @Select("select count(*) from cart_item where host_id = #{hostId} and g_id = #{gId}")
    Integer checkGoodsInCart(Integer gId, Integer hostId);

    // 查询自己买了什么增值服务
    @Select("select * from goods where g_id in (select g_id from cart_item where host_id = #{hostId})")
    List<Goods> getGoodsInCart(Integer hostId);


}
